﻿#include<Windows.h>
#include<CommCtrl.h> 

//windows信息处理函数
LRESULT CALLBACK Wndproc(
	HWND hwnd,
	UINT uMsg,
	WPARAM wParam,
	LPARAM lParam
)
{
	static HINSTANCE instance = GetModuleHandleW(NULL);
	switch (uMsg)
	{
		case WM_CREATE:
			CreateWindowW(WC_BUTTON, L"按钮1",
				WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles 
				10,         // x position 
				10,         // y position 
				100,        // Button width
				50,        // Button height
				hwnd,     // Parent window
				(HMENU)0x100,       // No menu.
				instance,
				NULL
			);
			CreateWindowW(WC_BUTTON, L"按钮2",
				WS_TABSTOP | WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,  // Styles 
				10,         // x position 
				90,         // y position 
				100,        // Button width
				50,        // Button height
				hwnd,     // Parent window
				(HMENU)0x101,       // No menu.
				instance,
				NULL
			);
			break;
		case WM_COMMAND:
			int menuNo = LOWORD(wParam);
			if (menuNo == 0x100) {
				MessageBoxW(NULL, L"按键1按下", 0, 0);
			}
			if (menuNo == 0x101) {
				MessageBoxW(NULL, L"按键2按下", 0, 0);
			}

	}
	return DefWindowProcW(hwnd, uMsg, wParam, lParam);
}


int WINAPI WinMain(
	HINSTANCE hInstance,
	HINSTANCE preInstance,
	LPSTR lpCmdLine,
	int cmdStyle
)
{
	//创建一个窗口类
	WNDCLASSW myclass = {0};
	myclass.lpszClassName = L"zhuxian_waigua";
	myclass.lpfnWndProc = Wndproc;

	//注册窗口类
	RegisterClassW(&myclass);

	//创建窗口
	HWND hwnd = CreateWindowW(
		myclass.lpszClassName,
		L"ZX_waigua",
		WS_OVERLAPPEDWINDOW,
		CW_USEDEFAULT,
		0,
		CW_USEDEFAULT,
		100,
		NULL,
		NULL,
		hInstance,
		NULL
	);
	
	//显示窗口
	ShowWindow(hwnd, SW_SHOWNORMAL);

	MSG msg = { 0 };

	while (GetMessageW(&msg, NULL, 0, 0)) {
		DispatchMessageW(&msg);
	}


	return 0;
}